<template>
	<div>
		<el-menu style="width:150px;min-height:90vh "
		:default-active="path"
             router
		class="el-menu-vertical-demo">
<!--      当角色是role是1管理员的时候显示-->
			<el-sub-menu index="1" v-if="user.role===1">
				<template #title>系统管理</template>
					<el-menu-item index="/user">用户管理</el-menu-item>
			</el-sub-menu>
			<el-menu-item index="/book" >书籍管理</el-menu-item>
      <el-menu-item index="/news" v-if="user.role===2">新闻管理</el-menu-item>
		</el-menu>
	</div>
</template>

<script>
import request from "@/utils/request";

export default {
  name:'Aside',
  data(){
    return{
      user:{},
      path:this.$route.path//设置默认高亮
    }
},
  created() {
    let userStr=sessionStorage.getItem("user")||"{}"
    this.user=JSON.parse(userStr)

    //请求服务器，确认当前登录用户的合法信息
    request.get("/user/"+this.user.id).then(res =>{
      if(res.code==='0'){
        this.user=res.data
      }
    })
  }
}
</script>

<style></style>
